
<!DOCTYPE html>
<html>
<!-- 文档首页模板 -->
	<head>
		<meta charset="utf-8">
		<meta name="renderer" content="webkit">
		<title>enianAdmin-初始化</title>
		<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
		<link rel="stylesheet" href="/static/layui/css/layui.css" />
		<style type="text/css">
			html{
				background: #f2f2f2;
				width: 100%;
				height: 100%;
				line-height: 100%;
			}
			body{
				/*text-align: center;*/
				line-height: 100%;
				width: 80%;
				height: 100%;
				margin: auto;
				
				overflow-x: hidden;
				overflow-y: hidden;
			}
			.content{
				width: 100%;
				height: 500px;
				margin: auto;
				margin-top: 70px;
			}
			#content-body {
				height: 80%;
				width: 80%;
				margin: auto;
			}
			.this{
				color: gold;
			}
			.jiantou{
				color: darkgray;
			}
		</style>
	</head>

	<body>
		<div class="layui-card content" >
			<div class="layui-card-header">
				欢迎使用enianAdmin 请输入以下信息，系统将自动进行初始化配置
				<!--<a class="this">1.初始化</a><a class="jiantou"> -> </a> 2.生成数据表和生成配置文件<a class="jiantou"> -> </a>3.完成-->
			</div>
			<div class="layui-card-body" id="content-body">
				<form class="layui-form layui-form-pane" action="" plan>
				  <div class="layui-form-item">
				    <label class="layui-form-label">连接地址</label>
				    <div class="layui-input-block">
				      <input type="text" name="hostname"  lay-verify="" placeholder="请输入" value="localhost" autocomplete="off" class="layui-input">
				    </div>
				  </div>
				  <div class="layui-form-item">
				    <label class="layui-form-label">数据库名</label>
				    <div class="layui-input-block">
				      <input type="text" name="database" lay-verify="" placeholder="请输入数据库名" value="enian_admin" autocomplete="off" class="layui-input">
				    </div>
				  </div>
				  <div class="layui-form-item">
				    <label class="layui-form-label">用户名</label>
				    <div class="layui-input-block">
				      <input type="text" name="username" lay-verify="" placeholder="数据库用户名" autocomplete="off" value="root"  class="layui-input">
				    </div>
				  </div>
				  <div class="layui-form-item">
				    <label class="layui-form-label">密码</label>
				    <div class="layui-input-block">
				      <input type="password" name="password" lay-verify="" placeholder="密码" autocomplete="off" class="layui-input">
				    </div>
				  </div>
				  <!-- <div class="layui-form-item">
				    <label class="layui-form-label">端口</label>
				    <div class="layui-input-block">
				      <input type="text" name="hostport"  lay-verify="" placeholder="不填写使用默认：3306"  autocomplete="off" class="layui-input">
				    </div>
				  </div> -->
				  <div class="layui-form-item">
				    <label class="layui-form-label">数据表前缀</label>
				    <div class="layui-input-block">
				      <input type="text" name="prefix" lay-verify="" placeholder="下划线请自写"  value="enian_" autocomplete="off" class="layui-input">
				    </div>
				  </div>
				  <div class="layui-form-item">
				    <div class="layui-input-block">
				      <button class="layui-btn" lay-submit lay-filter="formDemo">提交</button>
				      <button type="reset" class="layui-btn layui-btn-primary">重置</button>
				    </div>
				  </div>
				</form>
			</div>
			
		</div>
		
		
		<script src="/static/layui/layui.js"></script>
		<script type="text/javascript">
			layui.use(['form','jquery','layer'], function(){
			  var info ; 
			  var form = layui.form,$=layui.jquery,layer=layui.layer;
			  
			  //监听提交
			  form.on('submit(formDemo)', function(data){
			  	info=data.field;
			    //layer.msg(JSON.stringify(data.field));
			    var url = '/install/php/?step=1';
			    var index = layer.load(2);
			    ajax(url,info,function(res){
				    	if(res.code==1){
			    			layer.close(index);     
			    			layer.msg('执行完成');
			    			step2()
			    		}else{
			    			layer.close(index);    
			    			layer.alert('数据库登录出错，请检查数据库登录信息填写是否正确');
			    		}
				 },function(){
				 	layer.close(index);    
			    		layer.alert('数据库登录出错，请检查数据库登录信息填写是否正确');
				 });
			    
			    return false;
			  });
			  
			  //生成数据库配置文件
			 function step2(){
			 	layer.confirm('执行完成，请问是否继续生成数据库配置文件？', {
				  btn: ['确定','取消'] //按钮
				}, function(){
					var index = layer.load(2);
					var url = '/install/php/?step=2';
					ajax(url,info,function(res){
				    	if(res.code==1){
				    		layer.close(index);     
				    		layer.msg('创建成功');
				    		step3();
				    	}else{
				    		layer.close(index);    
				    		layer.alert('创建失败，可能是没有写入权限');
				    	}
				 	},function(){
				 		layer.close(index);    
				    	layer.alert('创建失败，可能是没有写入权限');
				 	});
				}, function(){
				  step3();
				});
			 }
			 
			 //删除安装文件
			 function step3(){
			 	alert('本次初始化已经全部完成，为了安全起见系统将为你【强制】删除安装初始化文件夹。');
			 	var url = '/install/php/?step=3';
			 	var data=[];
			 	ajax(url,data,function(res){
			 		if(res.code==1){
			 			layer.alert('已删除，现在您可以放心使用了');
			 		}else{
			 			layer.alert('删除失败，请手动删除');
			 		}
			 	},function(){
			 		layer.alert('删除失败，请手动删除');
			 	});
			 }
			 
			 function ajax(url,data,success,error){
			 	$.ajax({
				    	type:"post",
				    	url:url,
				    	data:data,
				    	async:true,
				    	success:function(res){
				    		success(res);
				    	},
				    	error:function(res){
				    		error(res);
				    	}
				    });
			 }
			});
		</script>
		
	</body>

</html>	
	
